1 //+------------------------------------------------------------------+
\r
3 //+------------------------------------------------------------------+
\r
4 #property indicator_separate_window
\r
5 #property indicator_buffers 2
\r
6 #property indicator_color1 Red
\r
7 #property indicator_color2 Blue
\r
9 extern int COGPeriod = 10;
\r
11 double COG[], COG1[], wrkArray[];
\r
12 //+------------------------------------------------------------------+
\r
15 IndicatorBuffers(2);
\r
16 IndicatorDigits( MarketInfo( Symbol(), MODE_DIGITS ));
\r
17 SetIndexStyle(0, DRAW_LINE);
\r
18 SetIndexStyle(1, DRAW_LINE);
\r
20 if( !SetIndexBuffer( 0, COG ) &&
\r
21 !SetIndexBuffer( 1, COG1 ))
\r
22 Print( "cannot set indicator buffers!" );
\r
24 SetIndexDrawBegin( 0, COGPeriod );
\r
25 SetIndexDrawBegin( 1, COGPeriod );
\r
27 IndicatorShortName( "Ehlers COG" );
\r
31 //+------------------------------------------------------------------+
\r
32 // Calculating Ehlers Center of Gravity
\r
33 //+------------------------------------------------------------------+
\r
34 // COG = -1 * (NUM / DENOM)
\r
35 // NUM = the sum of [PRICE[i] * (i + 1)] from 0 to N
\r
36 // DENOM = the sum of PRICE[i] from 0 to N
\r
37 // where N equals the number of periods (COGPeriod)
\r
38 // PRICE[0] equals the current bar
\r
39 // PRICE[1] equals the previous bar
\r
40 // PRICE[n] equals the price from n bars previous
\r
41 //+------------------------------------------------------------------+
\r
44 int i, j, limit, iWrk00;
\r
45 int countedBars = IndicatorCounted();
\r
46 double dWrk00, num, denom;
\r
48 limit = Bars - countedBars;
\r
49 for( i = 0; i < limit; i++ )
\r
51 if((i >= COGPeriod) || (limit < 10))
\r
55 for( j = 0; j < COGPeriod; j++)
\r
60 iWrk00 = i - COGPeriod + j;
\r
61 dWrk00 = (High[iWrk00] + Low[iWrk00]) / 2;
\r
62 num = num + (1 + j) * dWrk00;
\r
63 denom = denom + dWrk00;
\r
68 iWrk00 = i - COGPeriod;
\r
69 COG[iWrk00] = -num / denom;
\r
71 COG1[iWrk00 - 1] = COG[iWrk00];
\r
77 //+------------------------------------------------------------------+ It doesn't seem to be charting out for me
\r